<?php echo isset($warning) ? '<div class="alert bg-danger">'.$warning.'</div>' : "" ?>
<?php echo isset($notify) ? '<div class="alert alert-success">'.$notify.'</div>' : "" ?>
<form class="form-horizontal" role="form" method="post" action="<?=site_url('user/index') ?>">  
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Tìm kiếm</label>    
    <div class="col-sm-6">
      <div class="col-sm-5">
        <input type="text" name="search" class="form-control" id="inputPassword3" placeholder="Nhập tên cần tìm.." value="<?=isset($search) ? $search : "" ?>">     
      </div>               
      <div class="col-sm-5">
        <select class="form-control" onchange="this.form.submit()" name="user_cat">
          <option value="all">--Tất cả--</option>
          <option value="1" <?=(!empty($user_cat) && ($user_cat == 1)) ? 'selected' : '' ?>>Người dùng</option>
          <option value="2" <?=(!empty($user_cat) && ($user_cat == 2)) ? 'selected' : '' ?>>Cộng tác viên</option>          
        </select>
      </div>
    </div>          
  </div>
  <!--
  <div class="form-group">
  <label for="inputPassword3" class="col-sm-2 control-label">Chọn ngày</label>    
    <div class="container">
      <div class="col-sm-6">
         <div class='col-md-5' style="margin-right:10px;">
              <div class="form-group">
                  <div class='input-group date' id='datetimepicker8'>
                      <input type='text' name="fromDate" class="form-control" placeholder="Chọn từ ngày" value="<?=isset($fromDate) ? $fromDate : "" ?>" />
                      <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span>
                      </span>
                  </div>
              </div>
          </div>              
          <div class='col-md-5' style="">
              <div class="form-group">
                  <div class='input-group date' id='datetimepicker9'>
                      <input type='text' name="toDate" class="form-control" placeholder="tới ngày" value="<?=isset($toDate) ? $toDate : "" ?>"/>
                      <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span>
                      </span>
                  </div>
              </div>
          </div>
      </div>    
      <script type="text/javascript">
          $(function () {
              $('#datetimepicker8').datetimepicker();
              $('#datetimepicker9').datetimepicker();
              $("#datetimepicker8").on("dp.change",function (e) {
                 $('#datetimepicker9').data("DateTimePicker").setMinDate(e.date);
              });
              $("#datetimepicker9").on("dp.change",function (e) {
                 $('#datetimepicker8').data("DateTimePicker").setMaxDate(e.date);
              });
          });
      </script>
      <button type="submit" class="btn btn-primary">Tìm kiếm</button></td>    
    </div> 
  </div>   
  -->
</form>

<!-- Tạo người dùng mới -->
<p>
  <a id="go" rel="leanModal" name="signup" class="btn btn-primary" href="#signup">Tạo người dùng mới</a> 
</p>
<!-- Tạo người dùng mới -->

<?php if(!empty($users)): ?>
<div class="table-responsive">
  <table class="table table-bordered">
    <thead>
      <tr class="info" align="center">
        <td>STT</td>               
        <td>Tài khoản</td>
        <td>Hình ảnh</td>
        <td>Email</td>
        <td>Ngày tạo</td>
        <td colspan="2">Phân quyền</td>
        <td>Kích hoạt</td>                            
        <td>Thao tác</td>           
      </tr>
    </thead>
    <tbody>
    <script type="text/javascript">
        var wasSubmitted = false;    
          function checkBeforeSubmit(){
            if(!wasSubmitted) {
              wasSubmitted = true;
              return wasSubmitted;
            }
            return false;
          }    
      </script>
      <?php 
        $i = 1;     
        foreach ($users as $row):   

        $is_active = !empty($row->active) ? '<button type="button" class="btn btn-success"><span class="glyphicon glyphicon-ok-sign"></span></button>' : '<button type="button" class="btn btn-danger"><span class="glyphicon glyphicon-remove-sign"></span></button>';
        $is_view = !empty($row->is_view) ? '<button type="button" class="btn btn-success">Xem</button>' : '';
        $is_edit = !empty($row->is_edit) ? '<button type="button" class="btn btn-success">Chỉnh sửa</button>' : '';
        $tr_class = empty($row->active) ? 'danger' : '';        

          echo '<form id="form'.$i.'" action="'.site_url('user/edit/'.$row->id).'" method="post">';               
          echo '<tr align="center" class="'.$tr_class.'">
                  <td>'.$i.'</td>              
                  <td>'.$row->username.'</td>              
                  <td><img src="'.base_url('uploads/image/designer/'.$row->image).'" style="width:80%"/></td>
                  <td>'.$row->email.'</td>
                  <td>'.$row->created_date.'</td>
                  <td>'.$is_view.'</td>
                  <td>'.$is_edit.'</td>
                  <td>'.$is_active.'</td>                                    
                  <td>
                    <button class="btn btn-primary"><span class="glyphicon glyphicon-pencil"></span> Chỉnh sửa</button>                                        
                  </td>              
                </tr>';           
          echo '</form>';            
          $i++;
        endforeach;
      ?>
    </tbody>
  </table>
  <?= !empty($paging_users) ? "<div class='pull-right'><span>Tổng cộng: $total người dùng</span><br>$paging_users</div>" : "" ?>  
</div>		
<?php endif; ?>

<!-- Show create user form -->
<div id="signup">
      <div id="signup-ct">
        <div id="signup-header">
          <h2>Tạo tài khoản mới</h2>
          <p></p>
          <a class="modal_close" href="#"></a>
        </div>        
        <form action="<?=site_url('user/newUser') ?>" method="post">     
          <div class="txt-fld">
            <label for="">Tài khoản</label>
            <input id="" class="good_input" name="username" type="text" />
          </div>                  
          <div class="txt-fld">
            <label for="">Tên đầy đủ</label>
            <input id="" class="good_input" name="fullname" type="text" />
          </div>
          <div class="txt-fld">
            <label for="">Email</label>
            <input id="" class="good_input" name="email" type="text" />
          </div>   
          <div class="txt-fld">                 
            <select class="form-control" name="user_cat">
              <option value="1">Người dùng</option>
              <option value="2">CTV</option>              
            </select>       
          </div>
          <div class="btn-fld">
            <button type="submit" name="createBtn" value="createBtn_value">Khởi tạo</button>
          </div>
         </form>
      </div>
</div>